package com.sss.service.impl;

import com.sss.dao.GoodsMapper;
import com.sss.entity.Goods;
import com.sss.service.GoodsService;
import com.sss.util.PageUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional
@Service("goodsService")
public class GoodsServiceImpl implements GoodsService {
    private GoodsMapper goodsMapper;

    @Resource(name = "goodsMapper")
    public void setGoodsMapper(GoodsMapper goodsMapper){
        this.goodsMapper=goodsMapper;
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public boolean add(Goods goods) {
        return goodsMapper.insertOne(goods)>0;
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public boolean update(Goods goods) {
        return goodsMapper.updateOne(goods)>0;
    }


    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public List<Goods> getList() {
        return goodsMapper.select();
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public Goods get(String goodsname, Integer id) {

        return goodsMapper.selectOne(goodsname,id);
    }

    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    @Override
    public Integer getTotal(String goodsname) {
        return goodsMapper.selectTotal(goodsname);
    }

    @Override
    public Integer deleteOne(Integer id) {
        return goodsMapper.delete(id);
    }
}
